<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/3
 * Time: 15:21
 *
 * 
 */
function LendBook(){
    echo "请您输入书号：";
    $book_id = trim(fgets(STDIN));
    echo "请输入学号:";
    $number = trim(fgets(STDIN));
    echo "请输入您的姓名:";
    $reader_name = trim(fgets(STDIN));
    echo "请输入书名:";
    $book_name = trim(fgets(STDIN));
//连接数据库
    $dsn = 'mysql:dbname=school;host=192.168.137.2';
    $user = 'root';
    $password = '123456';
    $db = new PDO($dsn, $user, $password);
    try {
        $aaa = $db->exec("insert into record (rid,bid,rname,bname)VALUES
    ('$number','$book_id','$reader_name','$book_name')");
        if ($aaa) {
            echo "语句对了\n";
        } else if ($aaa === false) {
            echo "语句出错\n";
        } else {
            echo "内容为空，请联系管理员：110\n";
        }
    } catch (PDOException   $e) {
        echo 'Connection failed:' . $e->getMessage();
        echo "\n";
    }
//显示结果
    $aaa = ($db->query("select * from record"));
    $temp = $aaa->fetchAll(PDO::FETCH_ASSOC);
    print_r($temp);

//借书时限为一个月
    $borrowTime = date('Y-m-d');
    $backTime = date("Y-m-d", (time() + 3600 * 24 * 30));
    echo "借书成功，请于" . $backTime . "内归还！\n";
}